#define _CRT_SECURE_NO_WARNINGS 1
#pragma once
#include <iostream>
#include <assert.h>
using namespace std;

namespace bit
{
	class String
	{
	public:
		//基本结构
		typedef char* iterator;
		typedef const char* const_iterator;
		
		iterator begin();
		iterator end();
		
		const_iterator begin() const;
		const_iterator end() const;

		//String();
		String(const char* str = "");//ȫȱʡ
		String(const String& s);		   //拷贝构造
		//String& operator=(const String& s);//赋值
	
		String& operator=(String tmp);//赋值--> 现代写法2
		~String();
		const char* c_str() const;

		size_t size()const;
		char& operator[](size_t pos);
		const char& operator[](size_t pos) const;

		//相关接口
		void reserve(size_t n);

		void push_back(char ch);//追加字符
		void append(const char* str);//追加字符串

		String& operator+=(char ch);
		String& operator+=(const char* str);

		void insert(size_t pos, char ch);
		void insert(size_t pos, const char* str);
		void erase(size_t pos = 0, size_t len = npos);

		size_t find(char ch, size_t pos = 0);
		size_t find(const char* str, size_t pos = 0);

		void swap(String& s);
		String substr(size_t pos = 0, size_t len = npos);

		bool operator>(const String& s)const;
		bool operator<(const String& s)const;
		bool operator>=(const String& s)const;
		bool operator<=(const String& s)const;
		bool operator==(const String& s)const;
		bool operator!=(const String& s)const;
		
		void clear();
	private:
		char* _str = nullptr;
		size_t _size = 0;
		size_t _capacity = 0;
		const static size_t npos;
		//const static size_t npos = -1;   //特例，不建议这样写
	};

	istream& operator>> (istream& is, String& str);
	ostream& operator<< (ostream& os, const String& str);
}
